Followup r103865 and r103915
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 22 Nov 2011 23:10:22 +0000 (23:10 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 22 Nov 2011 23:10:22 +0000 (23:10 +0000)
r103915 added a parse error for 'more than 2 decimal points' in a number; this is the wrong place to check for that. Should only check whether there's more digits or identifier chars -- identifier chars would be illegal.

Added test cases for the exponent missing fails, tweaked it to be more consistent (only need to check for one e; if we have more we can lump them in with 'not digits' :)

Also cleaned up no-longer-needed suppress/restore warnings around JS parser invocation

tests/phpunit/includes/libs/JavaScriptMinifierTest.php

index d2bfeed..d7d3cf4 100644 (file)
@@ -89,8 +89,14 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
                        array( "var a = 5.;", "var a=5.;" ),
                        array( "5.0.toString();", "5.0.toString();" ),
                        array( "5..toString();", "5..toString();" ),
-                       array( "5...toString();", false ),
                        array( "5.\n.toString();", '5..toString();' ),
+
+                       /* Some structures that are invalid, that we may not detect */
+                       //array( "5...toString();", false ), // can't detect this yet, though JSParser will throw error
+                       array( '5e1', '5e1' ),
+                       array( "5e", false ), // no exponent (end)
+                       array( "5eee1", false ), // no exponent (multiple e)
+                       array( "5e++", false ), // no exponent (other symbol)
                );
        }
 
@@ -101,10 +107,7 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
                $minified = JavaScriptMinifier::minify( $code );
 
                // JSMin+'s parser will throw an exception if output is not valid JS.
-               // suppression of warnings needed for stupid crap
-               wfSuppressWarnings();
                $parser = new JSParser();
-               wfRestoreWarnings();
                $parser->parse( $minified, 'minify-test.js', 1 );
 
                $this->assertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." );